package com.qinghong.blog.vo;

import com.qinghong.blog.constant.StatusConst;
import com.qinghong.blog.enums.ResultCode;
import lombok.Data;

import java.io.Serializable;

/**
 * 接口返回类
 */
@Data
public class Result<T> implements Serializable {

    private Integer code;

    private String message;

    private T data;

    public Result(Integer code, String message, Object data) {
        this.code = code;
        this.message = message;
        this.data = (T) data;
    }

    public Result(ResultCode resultCode){
        this.code = resultCode.getCode();
        this.message = resultCode.getMessage();
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static Result success(String message){
        return new Result(StatusConst.OK,message);
    }

    public static Result success(String message,Object data){
        return new Result(StatusConst.OK,message,data);
    }

    public static Result error(String message){
        return new Result(StatusConst.ERROR,message);
    }

    public static Result error(ResultCode resultCode){
        return new Result(resultCode.getCode(),resultCode.getMessage());
    }

    public static Result error(String message,Object data){
        return new Result(StatusConst.ERROR,message,data);
    }

}
